﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApAPPZoneData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.AutomaticPathPlanner;
using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace DnProcessSimulateCommands;

public class CApAPPZoneData : INotifyPropertyChanged
{
  private List<string> m_zoneNames;
  private int m_rank;
  private readonly List<List<string>> m_orderedZoneReference;

  public event ZoneDataDidChangedEventHandler ZoneDataDidChanged;

  public CApAPPZoneData(
    string i_zoneName1,
    string i_zoneName2,
    string i_zoneName3,
    List<List<string>> i_orderedZoneReferences)
  {
    this.m_zoneNames = new List<string>();
    this.m_zoneNames.Add(i_zoneName1);
    this.m_zoneNames.Add(i_zoneName2);
    this.m_zoneNames.Add(i_zoneName3);
    this.m_orderedZoneReference = i_orderedZoneReferences;
    this.UpdateUniqueRank();
  }

  public bool CanZoneBeModified
  {
    get
    {
      int num1 = Math.Max(this.m_orderedZoneReference[0].IndexOf(this.Name1), 0);
      int num2 = Math.Max(this.m_orderedZoneReference[1].IndexOf(this.Name2), 0);
      int num3 = Math.Max(this.m_orderedZoneReference[2].IndexOf(this.Name3), 0);
      return num1 != 0 || num2 != 0 || num3 != 0;
    }
  }

  public List<string> Names => this.m_zoneNames;

  public string Name1
  {
    get => this.m_zoneNames[0];
    set
    {
      if (value == null)
        return;
      this.m_zoneNames[0] = value;
      this.UpdateUniqueRank();
      this.NotifyPropertyChanged(nameof (Name1));
      if (this.ZoneDataDidChanged == null)
        return;
      this.ZoneDataDidChanged((object) this, new EventArgs());
    }
  }

  public string Name2
  {
    get => this.m_zoneNames[1];
    set
    {
      if (value == null)
        return;
      this.m_zoneNames[1] = value;
      this.UpdateUniqueRank();
      this.NotifyPropertyChanged(nameof (Name2));
      if (this.ZoneDataDidChanged == null)
        return;
      this.ZoneDataDidChanged((object) this, new EventArgs());
    }
  }

  public string Name3
  {
    get => this.m_zoneNames[2];
    set
    {
      if (value == null)
        return;
      this.m_zoneNames[2] = value;
      this.UpdateUniqueRank();
      this.NotifyPropertyChanged(nameof (Name3));
      if (this.ZoneDataDidChanged == null)
        return;
      this.ZoneDataDidChanged((object) this, new EventArgs());
    }
  }

  public string UniqueName => CApAPPZoneData.GenerateUniqueName(this.Name1, this.Name2, this.Name3);

  public static string GenerateUniqueName(string zoneName1, string zoneName2, string zoneName3)
  {
    return $"__{zoneName1}_{zoneName2}_{zoneName3}__";
  }

  public int UniqueRank
  {
    get => this.m_rank;
    private set
    {
      this.m_rank = value;
      this.NotifyPropertyChanged(nameof (UniqueRank));
    }
  }

  private void UpdateUniqueRank()
  {
    this.UniqueRank = CUiAPPGeneralSettings.ComputeZoneDataRank(Math.Max(this.m_orderedZoneReference[0].IndexOf(this.Name1), 0), Math.Max(this.m_orderedZoneReference[1].IndexOf(this.Name2), 0), Math.Max(this.m_orderedZoneReference[2].IndexOf(this.Name3), 0));
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected void NotifyPropertyChanged(string info)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(info));
  }
}
